/* jshint indent: 2 */
module.exports = (app) => {
  const sequelize = app.model;
  const DataTypes = app.Sequelize.DataTypes;
  const Comment = sequelize.define('comment', {
    id: {
      type: DataTypes.INTEGER(11),
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
    },
    comment: {
      field: 'text',
      type: DataTypes.STRING(255),
      comment: '评论文字',
    },
    status: {
      type: DataTypes.INTEGER(1),
      defaultValue: 0,
      comment: '状态，0:未查看，1:已查看',
    },
  }, {
    createdAt: 'create_time', // 记录创建时间
    updatedAt: 'update_time', // 记录更新时间
    freezeTableName: true, // 不允许修改表名
  });

  Comment.associate = () => {
    app.model.Comment.belongsTo(app.model.User, {
      as: 'creator',
      foreignKey: 'creatorId',
    });
    app.model.Comment.belongsTo(app.model.User, {
      as: 'at',
      foreignKey: 'atId',
    });
    // app.model.Comment.belongsTo(app.model.Article, {
    //   as: 'article',
    //   foreignKey: 'articleId',
    // });
  };
  return Comment;
};
